package cn.com.huzo.repository.master.impl;

import cn.com.huzo.model.entities.master.ArrivalAllowedEntity;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;
import cn.com.huzo.repository.master.ArrivalAllowedRepository;

/**
 * 到货允许数据访问对象。
 *
 * @author 吴旭
 */
@Repository("ArrivalAllowedRepository")
public class ArrivalAllowedRepositoryImpl extends GenericRepositoryImpl<ArrivalAllowedEntity, Long>
        implements ArrivalAllowedRepository {

    private final String namespace = "cn.com.huzo.repository.master.ArrivalAllowedRepository";

    /**
     * 构造函数,设置the entity to ArrivalAllowedRepositoryImpl.class.
     */
    public ArrivalAllowedRepositoryImpl() {
        super(ArrivalAllowedEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ArrivalAllowedEntity fetchByKey(Long key) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchByKey"), key);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer fetchForCount(Map<String, Object> criterion) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForCount"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<ArrivalAllowedEntity> fetchForPage(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForPage"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Long insert(ArrivalAllowedEntity instance) {
        getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insert"), instance);

        // 返回出入后的记录ID
        return instance.getAllowanceId();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchInsert(List<ArrivalAllowedEntity> itemList) {
        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchInsert"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchUpdate(List<ArrivalAllowedEntity> itemList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchUpdate"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer delete(Long key) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "delete"), key);
    }
}
